package mapper;

import cn.itcast.pojo.User;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class userDaoImpl implements IUserDao {
      private SqlSession sqlSession;
      public userDaoImpl(SqlSession sqlSession){
          this.sqlSession=sqlSession;
      }
    public User queryUserById(Long id) {
        User user = sqlSession.selectOne("UserDaoMapper.queryUserById", 4l);
            return user;
    }

    public List<User> queryUserList() {
        List<User> list = sqlSession.selectList("UserDaoMapper.queryUserList");
        return list;
    }

    public void addUser(User user) {
        int count = sqlSession.insert("UserDaoMapper.addUser", user);
        System.out.println(count);
       sqlSession.commit();
    }

    public void updateUser(User user) {
        int count = sqlSession.update("UserDaoMapper.updateUser", user);
        System.out.println(count);
        sqlSession.commit();

    }

    public void deleteUserById(Long id) {
        int delete = sqlSession.delete("UserDaoMapper.deleteUserById", id);
        System.out.println(delete);
             sqlSession.commit();
    }
}
